﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;


using LocalDatabase.Model;


namespace FindMe
{
    public partial class locationName : UserControl
    {
        public locationName()
        {
            InitializeComponent();
        }

        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            if (txtLocationName.Text == String.Empty || txtLocationName.Text == "Enter Location")
            {
                MessageBox.Show("please enter a Location Name");
            }
            //this.Type = "Images/orbz-fire.png";
            //Confirm there is some text in the text box.
            else if (txtLocationName.Text.Length > 0)
            {
                // Create a new to-do item.
                FavoriteLocation newLocation = new FavoriteLocation()
                {
                    Name = txtLocationName.Text,
                    Location = App.UserCoordinates
                };

                // Add the item to the ViewModel.
                App._FavoriteLocationsViewModel.AddLocation(newLocation);
                //FindMeDataContext db = new FindMeDataContext();
                //var locations = from l in db.FavoriteLocations select l;
                //MessageBox.Show("Locations in DB: " + locations.Count().ToString());
                ClosePopup();
            }
        }


        private void txtLocationName_MouseEnter(object sender, MouseEventArgs e)
        {
            if (txtLocationName.Text == "Enter Location")
            {
                txtLocationName.Text = String.Empty;
            }
        }

        private void txtLocationName_MouseLeave(object sender, MouseEventArgs e)
        {
            if (txtLocationName.Text == String.Empty)
            {
                txtLocationName.Text = "Enter Location";
            }
        }

        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            ClosePopup();
        }

        private void ClosePopup()
        {
            Popup Pop = this.Parent as Popup;
            Pop.IsOpen = false;                       
        }

   }
}
